<?php

$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'),
    require(__DIR__ . '/../../common/config/params-local.php'),
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/params-local.php')
);

return [
    'id' => 'app-backend',
    'basePath' => dirname(__DIR__),
    'controllerNamespace' => 'backend\controllers',
    'bootstrap' => ['log'],
    'modules' => [
        'admin' => [
            'class' => 'mdm\admin\Module',
        ],
        'redactor' => [
            'class' => 'backend\components\RedactorModule',
            'uploadDir' => '@webroot/uploads',
            'uploadUrl' => 'http://images.blog.com',
            'imageAllowExtensions' => ['jpg', 'png', 'gif']
        ],
    ],
    'aliases' => [
        '@mdm/admin' => '@vendor/mdmsoft/yii2-admin',
    ],
    'as theme' => [
        'class' => 'backend\components\ThemeControl',
    ],
    'components' => [
        'view' => [
            'theme' => [
                // 分别是对资源的目录和资源的url进行配置
                // 'basePath' => '@app/themes/spring',
                // 'baseUrl' => '@web/themes/spring',
                // 从名字上不难分析出其是路径的一个映射，说白了就是对@app/view路径替换为
                // todo 另外一种实现就是利用Controller发送参数的形式实现，这里先进行屏蔽
                /*'pathMap' => [
                    '@app/views' => [
                        '@app/themes/christmas',
                        '@app/themes/spring',
                    ]
                ],*/
            ],
        ],
        'assetManager' => [
            'bundles' => [
                'dmstr\web\AdminLteAsset' => [
                    'skin' => 'skin-blue-light',
                ],
            ],
        ],
        'request' => [
            'csrfParam' => '_csrf-backend',
        ],
        'user' => [
            'identityClass' => 'backend\models\UserBackend',
            'enableAutoLogin' => true,
        ],
        'session' => [
            // this is the name of the session cookie used for login on the backend
            'name' => 'advanced-backend',
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'authManager' => [
            'class' => 'yii\rbac\DbManager',
            'defaultRoles' => ['guest'],
        ],
        // 美化路由组件
        'urlManager' => [
            // 是否开启美化效果
            'enablePrettyUrl' => true,
            // 是否或略脚本名index.php
            'showScriptName' => false,
            // 是否开启严格解析路由
            'enableStrictParsing' => true,
            'suffix' => '.html',
            'rules' => [
                '<controller:\w+>/<action:\w+>/<page:\d+>' => '<controller>/<action>',// eg: /blog/index?page=2   ===>  /blog/index/2.html
                '<controller:\w+>/<id:\d+>' => '<controller>/view',// 将controller/id映射到controller/view界面 eg: /blog/view?id=3   ===> /blog/3.html
                '<controller:[0-9a-z\-]+>/<id:\d+>' => '<controller>/view',// 查看详细中间有横线的情况
                "<controller:[a-z0-9\-]+>/<action:[a-z0-9\-]+>" => "<controller>/<action>", // 匹配了Controller或Action中间有横线-的情况
                "<controller:\w+>/<action:\w+>" => "<controller>/<action>", // 默认的访问路径的规则
                "<module:\w+>/<controller:\w+>/<action:\w+>" => "<module>/<controller>/<action>", // index.php/admin/route/index  ===> /admin/route/index.html

                '' => 'site/index',// 设置首页
                '/index' => 'site/index',// 设置首页
            ],
        ],

    ],
    'params' => $params,
    // 'as myBehavior2' => MyBehavior::className(),
    'as access' => [
        'class' => 'mdm\admin\components\AccessControl',
        'allowActions' => [
            //这里是允许访问的action，不受权限控制
            //controller/action
            //'site/*',//允许访问的节点，可自行添加
            //'site/login','site/logout'
            '*'
        ]
    ],
];
